package com.iodemo;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUntilsDemo {

    public static void copy(OutputStream os, InputStream is) throws IOException {
        Integer buffSize = 1024 * 1024;
        copy(os,is,buffSize);
    }

        public static void copy(OutputStream os, InputStream is, Integer buffSize) throws IOException {
    if (os == null || is == null) {
        System.out.println("流不能为空");
    }
    if (buffSize <= 0) {
        System.out.println("缓冲值不能为0");
    }
    byte[] bytes = new byte[buffSize];
    int len;
    while ((len = is.read(bytes)) > 0) {
        os.write(bytes);
    }

}


    // IO 关闭流的方法
    public static void close(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
